package com.lys.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lys.commonutils.R;
import com.lys.eduservice.entity.EduCourse;
import com.lys.eduservice.entity.EduTeacher;
import com.lys.eduservice.service.EduCourseService;
import com.lys.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Lyyyys
 * @version 1.0
 * @date 2021/6/20 17:58
 */
@Api(description="前端讲师列表分页")
@RestController
@RequestMapping("/eduservice/teacherfront")
@CrossOrigin
public class  TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    //分页查询讲师的方法
    @ApiOperation(value = "分页查询讲师")
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> pageTeacher = new Page(page,limit);
        Map<String,Object> map = teacherService.getTeacherFrontList(pageTeacher);

        return R.ok().data("map",map);
    }

    //讲师详情的功能
    @ApiOperation(value = "根据ID查询讲师")
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){

        //1根据讲师id查询讲师基本信息
        EduTeacher eduTeacher = teacherService.getById(teacherId);
        //2根据讲师id查询所讲课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> eduCourseList = courseService.list(wrapper);

        return R.ok().data("teacher",eduTeacher).data("courseList",eduCourseList);
    }

}
